<template>
  <div class="app-container">
    <el-row style="margin-bottom: 1%">
      <el-col :span="8">
        <div class="titleClass">积分总额</div>
        <div class="titleContentClass">
          {{ productList.queryTotalPerformance || "0.00" }}
        </div>
      </el-col>
      <el-col :span="8">
        <div class="titleClass">贡献值</div>
        <div class="titleContentClass">
          {{ productList.userMoney ? productList.userMoney.allmoney : "0.00" }}
        </div>
      </el-col>
      <el-col :span="8">
        <div class="titleClass">累计释放</div>
        <div class="titleContentClass">
          {{ productList.userMoney ? productList.userMoney.maxmoney : "0.00" }}
        </div>
      </el-col>
    </el-row>
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="用户ID" prop="uid">
        <el-input
          v-model="queryParams.uid"
          placeholder="请输入用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入用户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邀请人ID" prop="invitee">
        <el-input
          v-model="queryParams.invitee"
          placeholder="请输入邀请人ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="大区业绩" prop="regionalPerformance">
        <el-input
          v-model="queryParams.regionalPerformance"
          placeholder="请输入大区业绩"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="小区业绩" prop="communityPerformance">
        <el-input
          v-model="queryParams.communityPerformance"
          placeholder="请输入小区业绩"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="交易地址" prop="tradingAddress">
        <el-input
          v-model="queryParams.tradingAddress"
          placeholder="请输入交易地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分享码" prop="share">
        <el-input
          v-model="queryParams.share"
          placeholder="请输入分享码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="级别" prop="superior">
        <el-select
          v-model="queryParams.superior"
          clearable
          placeholder="请选择"
        >
          <el-option
            v-for="item in superiorOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="登录状态" prop="canlogin">
        <el-select
          v-model="queryParams.canlogin"
          clearable
          placeholder="请选择"
        >
          <el-option
            v-for="item in canloginOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="提现状态" prop="canatm">
        <el-select v-model="queryParams.canatm" clearable placeholder="请选择">
          <el-option
            v-for="item in canatmOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="注册时间" prop="createTime">
        <el-date-picker
          v-model="ctime"
          type="daterange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="注册时间" prop="createTime">
        <DatePicker v-model="ctime" :timevalue1="ctime"></DatePicker>
      </el-form-item>
      <!--
       <el-form-item label="昵称" prop="nickName">
               <el-input
                 v-model="queryParams.nickName"
                 placeholder="请输入昵称"
                 clearable
                 size="small"
                 @keyup.enter.native="handleQuery"
               />
             </el-form-item>
       <el-form-item label="用户标识" prop="openid">
        <el-input
          v-model="queryParams.openid"
          placeholder="请输入用户标识"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="密码" prop="password">
         <el-input
           v-model="queryParams.password"
           placeholder="请输入密码"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
       <el-form-item label="性别" prop="gender">
         <el-input
           v-model="queryParams.gender"
           placeholder="请输入性别"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
       <el-form-item label="上级" prop="superior">
         <el-input
           v-model="queryParams.superior"
           placeholder="请输入上级"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
       <el-form-item label="真实姓名" prop="realName">
         <el-input
           v-model="queryParams.realName"
           placeholder="请输入真实姓名"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
       <el-form-item label="地址" prop="address">
         <el-input
           v-model="queryParams.address"
           placeholder="请输入地址"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
       <el-form-item label="通证额度" prop="quota">
         <el-input
           v-model="queryParams.quota"
           placeholder="请输入通证额度"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
       <el-form-item label="通证余额" prop="balanceQuota">
         <el-input
           v-model="queryParams.balanceQuota"
           placeholder="请输入通证余额"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
       <el-form-item label="现金余额" prop="cash">
         <el-input
           v-model="queryParams.cash"
           placeholder="请输入现金余额"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
       <el-form-item label="状态" prop="status">
         <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
           <el-option label="请选择字典生成" value="" />
         </el-select>
       </el-form-item>
      -->
      <el-form-item style="display: block">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ds:user:add']"
        >
          新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ds:user:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ds:user:remove']"
          >登录</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-coin"
          size="mini"
          :disabled="single"
          @click="dialogVisible = true"
          v-hasPermi="['ds:user:edit']"
          >质押</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-coin"
          size="mini"
          :disabled="single"
          @click="handleRecharge"
          v-hasPermi="['ds:user:edit']"
          >充值易货积分</el-button
        >
      </el-col>

      <!-- 充值绿色积分 -->
      <Recharge
        :uid="rechargeUid"
        @close="rechargeShow = false"
        @refresh="getList"
        :rechargeShow="rechargeShow"
      >
      </Recharge>

      <el-dialog
        title="请输入您的质押金额"
        :visible.sync="dialogVisible"
        width="30%"
        center
      >
        <div style="text-indent: 0.5em; color: #666; margin-bottom: 10px">
          您的YKGFC将扣除
          <span style="color: #ff4949"
            >{{ pledgePrice ? pledgePrice : "0" }} /
            {{ priceYKGFC ? priceYKGFC : "0" }} =
            {{
              (pledgePrice / priceYKGFC).toFixed(2)
                ? (pledgePrice / priceYKGFC).toFixed(2)
                : 0.0
            }}</span
          >
        </div>
        <el-input
          v-model="pledgePrice"
          placeholder="请输入质押金额"
          style="width: 50%"
        ></el-input>
        <span slot="footer" class="dialog-footer">
          <el-button @click="(pledgePrice = ''), (dialogVisible = false)"
            >取 消</el-button
          >
          <el-button type="primary" @click="pledgeUserYKGFC">确 定</el-button>
        </span>
      </el-dialog>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ds:user:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="userList"
      @selection-change="handleSelectionChange"
      border
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="会员信息" align="left">
        <template slot-scope="scope">
          <div>
            <div>UID: {{ scope.row.uid }}</div>
            <div>用户姓名: {{ scope.row.realName }}</div>
            <div>用户手机: {{ scope.row.phone }}</div>
            <div>级别: 游客</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="市场信息"
        class-name="small-padding fixed-width"
        width="250"
        align="left"
      >
        <template slot-scope="scope">
          <div>
            <div>好友: &nbsp;{{ scope.row.share }}</div>

            <div>
              总业绩: &nbsp;{{
                formatNumber(
                  Number.parseFloat(scope.row.communityPerformance) +
                    Number.parseFloat(scope.row.regionalPerformance) || 0
                )
              }}
            </div>
            <!-- <div>
              大区业绩: &nbsp;{{
                formatNumber(scope.row.regionalPerformance || 0)
              }}
            </div>
            <div>
              小区业绩: &nbsp;{{
                formatNumber(scope.row.communityPerformance || 0)
              }}
            </div> -->
            <div>
              好友人数: &nbsp;{{ formatNumber(scope.row.netBodyNumber || 0) }}
            </div>
            <div v-if="scope.row.tradingAddress">
              文艺通地址: &nbsp;{{ scope.row.tradingAddress || 0 }}
            </div>
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="账户资金"
        class-name="small-padding fixed-width"
        width="250"
        align="left"
      >
        <template slot-scope="scope">
          <div>
            <div>
              易货积分: &nbsp;{{ formatNumber(scope.row.rewardPoints || 0) }}
            </div>
            <div>
              消费积分: &nbsp;{{ formatNumber(scope.row.balanceQuota || 0) }}
            </div>
            <div>
              等待释放: &nbsp;{{ formatNumber(scope.row.notReleased || 0) }}
            </div>
            <div>
              总贡献值: &nbsp;{{ formatNumber(scope.row.totalOrder || 0) }}
            </div>
            <!-- <div>
              质押金额: &nbsp;{{ formatNumber(scope.row.pledge || 0) }}
            </div> -->
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="余额"
        class-name="small-padding fixed-width"
        width="250"
        align="left"
      >
        <template slot-scope="scope">
          <div>
            <div>
              消费积分: &nbsp;{{ formatNumber(scope.row.balanceQuota || 0) }}
            </div>
            <div>
              易货积分: &nbsp;{{ formatNumber(scope.row.rewardPoints || 0) }}
            </div>
            <!-- <div>YKGFC: &nbsp;{{ formatNumber(scope.row.yBalance || 0) }}</div>
            <div>
              GTFY2: &nbsp;{{ formatNumber(scope.row.gtfyBalance || 0) }}
            </div>
            <div>SZX: &nbsp;{{ formatNumber(scope.row.szxBalance || 0) }}</div>
            <div>
              绿色积分: &nbsp;{{ formatNumber(scope.row.greenPoints || 0) }}
            </div>
            <div>XYZ: &nbsp;{{ formatNumber(scope.row.xyzBalance || 0) }}</div> -->
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="充值易货积分">
        <template slot-scope="scope">
          <div>易货积分：{{ scope.row.rewardPoints }}</div>
          <div>
            <el-button type="primary" @click="rechargeRewardPoints(scope.row)"
              >充值</el-button
            >
          </div>
        </template>
      </el-table-column> -->
      <el-table-column
        label="开通情况"
        class-name="small-padding fixed-width"
        align="left"
      >
        <template slot-scope="scope">
          <div>
            <div>注册时间: &nbsp;{{ scope.row.createTime || "" }}</div>
            <div>
              是否可登录:
              <!-- <i class="el-icon-check" v-if="scope.row.canlogin==1" @click="updatecan(scope.row,'canlogin',0)"/>
              <i class="el-icon-close" v-else @click="updatecan(scope.row,'canlogin',1)"/> -->

              <el-switch
                v-model="scope.row.canlogin"
                active-color="#ff4949"
                inactive-color="#13ce66"
                :active-value="2"
                :inactive-value="1"
                @change="canLogin($event, scope.row)"
              >
              </el-switch>
            </div>
            <div>
              是否可提现:
              <el-switch
                v-model="scope.row.canatm"
                active-color="#ff4949"
                inactive-color="#13ce66"
                active-value="2"
                inactive-value="1"
                @change="canAtm($event, scope.row)"
              >
              </el-switch>
            </div>
            <!-- <div>
              是否可提现XYZ:
              <span>{{ scope.row.po == 1 ? "可以" : "不可以" }}</span>
              <el-switch
                v-model="scope.row.po"
                :active-value="1"
                :inactive-value="0"
                @change="canPo($event, scope.row)"
              >
              </el-switch>
            </div>
            <div>
              是否释放XYZ:
              <span>{{
                scope.row.wechatid == 1 || scope.row.wechatid == "1"
                  ? "释放"
                  : "不释放"
              }}</span>
              <el-switch
                v-model="scope.row.wechatid"
                active-value="1"
                inactive-value="0"
                @change="canSf($event, scope.row)"
              >
              </el-switch> 
            </div>-->
          </div>
        </template>
      </el-table-column>
      <el-table-column label="团队" width="100" align="center">
        <template slot-scope="scope">
          <el-button
            type="primary"
            v-hasPermi="['ds:user:team']"
            @click="checkGroup(scope.row)"
          >
            团队
          </el-button>
        </template>
      </el-table-column>

      <!-- <el-table-column label="用户名" align="center" prop="userName" class-name="small-padding fixed-width"/> -->
      <!-- <el-table-column label="邀约人" align="center" prop="share" /> -->
      <!--      <el-table-column label="邀请人" align="center" prop="inviteeSuperior" />-->
      <!--      <el-table-column label="邀请人列表" align="center" prop="superior" />-->
      <!-- <el-table-column label="手机号" align="center" prop="phone" class-name="small-padding fixed-width"/> -->
      <!--      <el-table-column label="贡献值" align="center" prop="quotab" />-->
      <!-- <el-table-column label="gtfy" align="center" prop="balanceQuota" /> -->
      <!-- <el-table-column label="消费积分" align="center" prop="money" /> -->
      <!-- <el-table-column label="提现" align="center" prop="canatm" />
            <el-table-column label="登陆" align="center" prop="canlogin" /> -->
      <!-- <el-table-column label="市场信息" align="left" class-name="small-padding fixed-width" width="250px"></el-table-column> -->
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-row style="margin-bottom: 5%">
            <el-col :span="12">
              <el-button
                type="primary"
                v-hasPermi="['ds:user:edit']"
                @click="handleUpdate(scope.row)"
                >修改</el-button
              >
            </el-col>
            <el-col :span="12">
              <el-button
                type="danger"
                v-hasPermi="['ds:user:remove']"
                @click="handleDelete(scope.row)"
                >登录</el-button
              >
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-button
                type="warning"
                v-if="scope.row.canlogin == 1"
                @click="canLogin(2, scope.row)"
                >冻结</el-button
              >
              <el-button type="info" v-else disabled>冻结</el-button>
            </el-col>
            <el-col :span="12">
              <el-button
                type="success"
                v-if="scope.row.canatm == 1"
                @click="canAtm(2, scope.row)"
                >提现</el-button
              >
              <el-button type="info" v-else disabled>提现</el-button>
            </el-col>
          </el-row>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <EnterCheckTeam ref="enterCheckTeam" />

    <!-- 弹出dialog -->
    <el-dialog
      :visible.sync="clientOpen"
      width="475px"
      append-to-body
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-draggable
      :modal="false"
    >
      <iframe
        ref="iframe"
        id="iframe"
        frameborder="0"
        :src="iframeSrc"
        style="min-height: 800px; width: 100%"
      >
      </iframe>
    </el-dialog>

    <!-- 添加或修改用户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        style="margin: 0 auto"
      >
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户名" />
        </el-form-item>
        <!--        <el-form-item label="密码" prop="password">-->
        <!--          <el-input v-model="form.password" placeholder="请输入密码" />-->
        <!--        </el-form-item>-->
        <el-form-item label="分享码" prop="userName">
          <el-input
            v-model="form.userName"
            placeholder="请输入分享码"
            disabled="disabled"
          />
        </el-form-item>
        <el-form-item label="上级列表" prop="superior">
          <el-input
            disabled="disabled"
            v-model="form.superior"
            placeholder="请输入上级"
          />
        </el-form-item>
        <el-form-item label="邀请人" prop="invitee">
          <el-input v-model="form.invitee" placeholder="请输入邀请人" />
        </el-form-item>
        <!--        <el-form-item label="邀请人上级" prop="inviteeSuperior">-->
        <!--          <el-input v-model="form.inviteeSuperior" placeholder="请输入邀请人上级" />-->
        <!--        </el-form-item>-->
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName">
          <el-input v-model="form.nickName" placeholder="请输入真实姓名" />
        </el-form-item>
        <!-- <el-form-item label="身份证号" prop="realName">
          <el-input disabled="disabled" v-model="form.idCard" placeholder="请输入真实姓名" />
        </el-form-item> -->
        <!-- <el-form-item label="银行卡" prop="realName">
          <el-input disabled="disabled" v-model="form.bankNo" placeholder="请输入真实姓名" />
        </el-form-item> -->
        <!--        <el-form-item label="地址" prop="address">-->
        <!--          <el-input v-model="form.address" placeholder="请输入地址" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="贡献值额度" prop="quota">-->
        <!--          <el-input v-model="form.quota" placeholder="请输入贡献值额度" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="通证余额" prop="balanceQuota">-->
        <!--          <el-input v-model="form.balanceQuota" placeholder="请输入通证余额" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="未释放额度" prop="balanceQuota">-->
        <!--          <el-input v-model="form.balanceQuota" placeholder="请输入未释放额度" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="消费积分余额" prop="quota">-->
        <!--          <el-input v-model="form.money" placeholder="请输入消费积分余额" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="现金余额" prop="cash">-->
        <!--          <el-input v-model="form.cash" placeholder="请输入现金余额" />-->
        <!--        </el-form-item>-->
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listUser,
  getUser,
  delUser,
  addUser,
  updateUser,
  exportUser,
  fastLogin,
  pledgeStore,
} from "@/api/ds/user";
import { listprice } from "@/api/ds/price";
// import { dataQuery } from "@/api/ds/productOrder";
import { getToken } from "@/utils/auth";
import ImageUpload from "@/components/ImageUpload";
import DatePicker from "@/components/DatePicker";
import valid from "../../../utils/validator";
import draggable from "./draggable";
import EnterCheckTeam from "./components/EnterCheckTeam.vue";
import Recharge from "./components/recharge/index.vue";

import {
  queryTotalPerformanceAndCashSales,
  queryActualPaymentAndContribution,
} from "@/api/ds/index";

export default {
  name: "User",
  components: {
    ImageUpload,
    DatePicker,
    EnterCheckTeam,
    Recharge,
  },
  directives: {
    draggable,
  },
  data() {
    return {
      ctime: [], //搜索框 时间选择器数据
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        uid: null,
        openid: null,
        nickName: null,
        avatarImage: null,
        userName: null,
        password: null,
        gender: null,
        share: null,
        idCard: null,
        bankNo: null,
        superior: null,
        invitee: null,
        inviteeSuperior: null,
        createTime: null,
        phone: null,
        realName: null,
        address: null,
        quota: null,
        balanceQuota: null,
        cash: null,
        status: null,
        canatm: null,
        canlogin: null,
        regionalPerformance: null, // 大区业绩
        communityPerformance: null, // 小区业绩
        create_time: "",
        endTime: "",
        tradingAddress: "",
      },
      // 表单参数
      form: {},
      superiorOptions: [
        // 级别下拉框
        { value: "0", label: "游客" },
        { value: "1", label: "一级" },
        { value: "2", label: "二级" },
      ],
      canatmOptions: [
        { value: 1, label: "可提现" },
        { value: 2, label: "不可提现" },
      ],
      canloginOptions: [
        { value: 1, label: "可登陆" },
        { value: 2, label: "不可登陆" },
      ],
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "用户名不能为空", trigger: "blur" },
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
        ],
        share: [{ required: true, message: "分享码不能为空", trigger: "blur" }],
        phone: [
          {
            required: true,
            validator: valid.telphone,
            message: "",
            trigger: ["change", "blur"],
          },
        ],
      },
      productList: [], // 产品数据
      iframeSrc: "",
      clientOpen: false,
      clientSrc: "",
      priceYKGFC: "",
      pledgePrice: "",
      dialogVisible: false,
      // 充值绿色积分
      rechargeShow: false,
      rechargeUid: "",
    };
  },
  computed: {
    formatNumber() {
      return (num) => {
        if (num) {
          num = num + "";
          let index = num.indexOf(".");
          if (index !== -1) {
            num = num.substring(0, 2 + index + 1);
          } else {
            num = num.substring(0);
          }
          return parseFloat(num).toFixed(2);
        } else {
          return "0.00";
        }
      };
    },
  },
  created() {
    this.iframeSrc = `http://data.web.gtfy.net.cn/#/`;

    this.getProductData();

    this.getList();
    this.getPriceList();
  },
  mounted() {
    // const self = this;
    // this.$nextTick(() => {
    //   const iframe = document.getElementById("iframe");
    // });
  },
  methods: {
    // rechargeRewardPoints(row){

    // },
    // 查看团队
    async checkGroup(row) {
      console.log(row);
      let uid = row.uid;
      let res = await fastLogin(uid);
      if (res.code === 200) {
        let token = res.data.token;
        // 显示
        this.$refs.enterCheckTeam.token = token;
        this.$refs.enterCheckTeam.show = true;
        this.$refs.enterCheckTeam.phone = row.phone;
      }
    },
    /** 查询分类信息列表 */
    getPriceList() {
      this.loading = true;
      listprice(this.queryParams).then((response) => {
        this.priceYKGFC = response.rows[0].yPrice;
        this.loading = false;
      });
    },

    updatecan(row, type, status) {
      var data = {};
      if (type == "canlogin") {
        data.canlogin = status;
      } else {
        data.canatm = status;
      }
      updateUser(data).then((response) => {
        this.msgSuccess("更新成功");

        this.getList();
      });
    },
    /** 是否可登陆 */
    canLogin(e, row) {
      row.canlogin = e;
      updateUser(row).then((response) => {
        this.msgSuccess("更新成功");
        this.getList();
      });
    },
    /** 是否可提现 */
    canAtm(e, row) {
      // let data = { canlogin: e , id : id}
      row.canatm = e;
      updateUser(row).then((response) => {
        this.msgSuccess("更新成功");
        this.getList();
      });
    },
    canSf(e, row) {
      console.log(
        "%c [ e ]-722",
        "font-size:13px; background:pink; color:#bf2c9f;",
        e
      );
      row.wechatid = e;
      updateUser(row).then((response) => {
        this.msgSuccess("更新成功");
        this.getList();
      });
    },
    canPo(e, row) {
      // let data = { canlogin: e , id : id}
      row.po = e;
      updateUser(row).then((response) => {
        this.msgSuccess("更新成功");
        this.getList();
      });
    },
    async handleRecharge() {
      this.rechargeShow = true;
    },
    /** 查询积分贡献值累计释放 */
    async getProductData() {
      // dataQuery().then((response) => {
      //   this.productList = JSON.parse(JSON.stringify(response)).data;
      //   this.loading = false;
      //   this.show = true;
      // });

      let res1 = await queryTotalPerformanceAndCashSales();

      if (res1.code === 200) {
        this.productList = res1.data;
      }

      let res2 = await queryActualPaymentAndContribution();
      if (res2.code === 200) {
        this.productList = Object.assign(this.productList, res2.data);
      }

      this.loading = false;
      this.show = true;
    },
    /** 查询用户信息列表 */
    getList() {
      this.loading = true;
      // let that = this;
      // this.queryParams.create_time = this.ctime[0]
      // this.queryParams.endTime = this.ctime[1]

      let q = this.addDateRange(this.queryParams, this.ctime, "");

      listUser(q).then((response) => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uid: null,
        openid: null,
        nickName: null,
        avatarImage: null,
        userName: null,
        password: null,
        gender: null,
        share: null,
        superior: null,
        invitee: null,
        inviteeSuperior: null,
        phone: null,
        realName: null,
        address: null,
        quota: null,
        balanceQuota: null,
        cash: null,
        status: 0,
        remark: null,
        createTime: null,
        canatm: null,
        canlogin: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      (this.ctime = []), this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(
        "%c [ selection ]-1015",
        "font-size:13px; background:#333333; color:#f3f3f3;",
        selection
      );
      this.ids = selection.map((item) => item.uid);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      if (this.ids.length === 1) {
        this.rechargeUid = this.ids[0];
        console.log(
          "%c [ this.rechargeUid ]-1025",
          "font-size:13px; background:#333333; color:#f3f3f3;",
          this.rechargeUid
        );
      } else {
        this.rechargeUid = "";
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户信息";
    },
    /** 冻结or提现 */
    updateInfo(row, type) {
      this.$confirm("此操作将修改状态, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then((res) => {
        if (type == "1") {
          // 冻结
          this.canLogin("2", row.uid);
        } else if (type == "2") {
          //提现
          this.canAtm("2", row.uid);
        }
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const uid = row.uid || this.ids;
      getUser(uid).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.uid != null) {
            updateUser(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 一键登录按钮操作 */
    handleDelete(row) {
      const uid = row.uid || this.ids;
      this.$confirm('是否一键登录"' + row.userName + '"此用户', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        fastLogin(uid).then((res) => {
          if (res.code === 200) {
            let token = res.data.token;
            this.iframeSrc = `http://data.web.gtfy.net.cn/#/?token=${token}`;
            // this.iframeSrc = `http://test.web.rfnpbag.cn/#/?token=${token}`;
            // this.iframeSrc = `http://192.168.9.116:8080/#/?token=${token}`;
            this.clientOpen = true;
          }
        });
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有用户信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportUser(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
    pledgeUserYKGFC() {
      const uid = this.ids;
      console.log(this.ids);

      if (this.pledgePrice) {
        pledgeStore({ uid: this.ids[0], price: this.pledgePrice }).then(
          (res) => {
            if (res.code === 200) {
              this.$message({
                type: "success",
                message: "你的质押金额是: " + this.pledgePrice,
              });
              this.handleQuery();
              this.pledgePrice = "";
            } else {
              this.$message({
                type: "info",
                message: "质押失败",
              });
              this.pledgePrice = "";
            }
          }
        );
      } else {
        this.$message.error("请输入金额");
      }
      this.dialogVisible = false;
    },
  },
};
</script>

<style scoped>
.el-form-item {
  margin-bottom: 0.5%;
}

.flex {
  display: flex;
  align-items: center;
}

.el-icon-check {
  font-size: 24px;
  color: green;
}

.el-icon-close {
  font-size: 24px;
  color: red;
}

.titleClass {
  background: lightgray;
  text-align: center;
  font-size: 18px;
  padding: 1%;
}

.titleContentClass {
  text-align: center;
  color: red;
  border: 1px solid lightgray;
  font-size: 18px;
  padding: 1%;
}
</style>
